package com.dadi.mashangkaixue

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity

/**
 *  Kotlin的变量、函数和类型(练习题)
 */
class MainActivity<T> : AppCompatActivity() {
    companion object {
        const val TAG = "MainActivity"
    }
    private lateinit var btnLogin : Button
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        btnLogin = findViewById(R.id.btn)
        println("登录ViewId: " + getViewId(btnLogin))
/*        println("账户ViewId: " + getViewId(account))
        println("密码ViewId :" + getViewId(password))*/
        // 创建类的实例时我们需要指定类型参数
        val box : Box<Int> = Box<Int>(1)
        val box1 = Box(1)
    }
   private fun getViewId(view : View?){
    val string = view.toString()
       Log.i(TAG, "View? id is $string")
       btnLogin.text = view?.id.toString()
   }
    fun <T> fill(array : Array<in T>, t : T){
        array[0] = t
    }
    fun <T> copy(srcArray : Array<out T>, destArray : Array<in T>){
       for (i in srcArray.indices) {
           destArray[i] = srcArray[i]
       }
    }
}
